Public Class DiagnosePrice

    Protected _year As String
    Protected _diagnose As New DiagnoseType()
    Protected _price As Double
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property Diagnose() As DiagnoseType
        Get
            Return _diagnose
        End Get
        Set(ByVal value As DiagnoseType)
            _diagnose = value
        End Set
    End Property

    Public Property price() As Double
        Get
            Return _price
        End Get
        Set(ByVal value As Double)
            _price = value
        End Set
    End Property

    Public Function getYearDiagnosePrice() As System.Data.DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_DiagnoseYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "DiagonosetYear")

        Return objDs
    End Function

    Public Function getsYearDiagnosePrice() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_DiagnoseYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "DiagonosetYear")

        For Each objDr As System.Data.DataRow In objDs.Tables("DiagonosetYear").Rows
            Dim obj As DiagnosePrice = New DiagnosePrice()
            obj.year = objDr.Item("year").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function getAllDiagnosePriceByYear(ByVal inYear As String) As System.Data.DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_DiagnosePriceByYear"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "DiagonosetPrice")

        Return objDs
    End Function

    Public Function getsAllDiagnosePriceByYear(ByVal inYear As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_DiagnosePriceByYear"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "DiagonosetPrice")

        For Each objDr As System.Data.DataRow In objDs.Tables("DiagonosetPrice").Rows
            Dim obj As DiagnosePrice = New DiagnosePrice()
            obj.year = objDr.Item("year").ToString()
            obj.Diagnose.diagnose_type_id = objDr.Item("diagnose_type_id").ToString()
            obj.Diagnose.diagnose_type_name = objDr.Item("diagnose_type_name").ToString()
            obj.price = objDr.Item("price").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function insertDiagnosePrice(ByVal inDiagnosePrice As DiagnosePrice) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_DiagnosePrice"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inDiagnosePrice.year)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inDiagnoseTypeID", inDiagnosePrice.Diagnose.diagnose_type_id)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inPrice", inDiagnosePrice.price)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function insertNewYearDiagnosePrice(ByVal inYear As String) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_NewYearDiagnosePrice"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _year = _Data(_DataCurrent).year
            _diagnose.diagnose_type_id = _Data(_DataCurrent).diagnose.diagnose_type_id
            _diagnose.diagnose_type_name = _Data(_DataCurrent).diagnose.diagnose_type_name
            _price = _Data(_DataCurrent).price
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub LoadDiagnosePriceByYear(ByVal inYear As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsAllDiagnosePriceByYear(inYear)
    End Sub

    Public Sub LoadDiagnoseYear()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsYearDiagnosePrice()
    End Sub

End Class
